#include <climits>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    vector<int> f(n + 1, INT_MAX);
    f[1] = 0;
    queue<int> q;
    q.push(1);
    while (q.size()) {
        auto t = q.front();
        q.pop();
        if (a[t] > 0) {
            for (int i = 1; i <= a[t]; i++) {
                if (i + t <= n && f[i + t] > f[t] + 1) {
                    f[i + t] = f[t] + 1;
                    q.push(i + t);
                }
            }
        }
        else {
            for (int i = t + a[t]; i > 0; i--) {
                if (f[i] > f[t] + 1) {
                    f[i] = f[t] + 1;
                    q.push(i);
                }
            }
        }
    }
    if (f[n] == INT_MAX) cout << -1 << endl;
    else cout << f[n] << endl;
    return 0;
}